package com.tfswx.jcyw.dmzc.window;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.ui.jcef.JBCefBrowser;
import com.tfswx.jcyw.dmzc.linstener.MyAppLifecycleListener;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;

/**
 * @author ricky
 * @date 2023/3/13
 */
public class TestDialogWrapper extends DialogWrapper {
    private final Project project;
    private final JBCefBrowser jbCefBrowser;

    public TestDialogWrapper(@NotNull Project project) {
        super(false);
        this.project = project;
        setTitle("添加走查记录");
        setSize(1300, 800);
        jbCefBrowser = new JBCefBrowser("http://localhost:" + MyAppLifecycleListener.SERVER_PORT + "?gcmc=" + project.getName());
        init();
    }

    @Override
    protected @Nullable JComponent createCenterPanel() {
        return jbCefBrowser.getComponent();
    }

    @Override
    protected void doOKAction() {
        jbCefBrowser.getCefBrowser().executeJavaScript("javascript:submit()", null, 0);
    }

    @Override
    protected Action @NotNull [] createActions() {
        Action okAction = getOKAction();
        okAction.putValue(Action.NAME, "提交");
        return new Action[]{okAction};
    }
}
